/**
 * 
 */
package com.fitnessapp.main;

import com.fitnessapp.database.DatabaseHelper;
import com.fitnessapp.user.User;

import android.app.Application;
import android.content.res.Configuration;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;


/**
 * @author Brett
 *
 */
public class FitnessApplication extends Application {
	
	private User currentUser;
	private SQLiteOpenHelper database;

	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);
	}

	@Override
	public void onCreate() {
		super.onCreate();		
		//make sure we have a local host in the db
		database = new DatabaseHelper(this);
		SQLiteDatabase db = database.getWritableDatabase();
		
		String query = "INSERT OR IGNORE INTO " + DatabaseHelper.USER_TABLE + " (" + DatabaseHelper.USER_TABLE_USERNAME + 
				") VALUES ('" + DatabaseHelper.LOCAL_USER + "')";
		
		Log.d("", query);
		
		Log.d("", db.rawQuery(query, null).getCount() + "");
		
		//load the user		
		currentUser = new User();
		currentUser.loadLocalUser(database.getReadableDatabase());		
	}

	@Override
	public void onLowMemory() {
		super.onLowMemory();
	}

	@Override
	public void onTerminate() {
		super.onTerminate();
	}
	
	public User getUser(){ return currentUser; }
	
	/**
	 * Load the local user from the database
	 */
	private void loadLocalUser(){
		
	}
	
	public SQLiteDatabase getDatabseReader() { return database.getReadableDatabase(); }
	public SQLiteDatabase getDatabseWriter() { return database.getWritableDatabase(); }
	

	
}
